#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    ui->pushButton->setEnabled(false);

    ui->lineEdit->setPlaceholderText("请输入电话");
    ui->lineEdit->setClearButtonEnabled(true);

    // 基于正则表达式设置验证器，添加约束
    QRegExp regExp("^1\\d{10}$");
    ui->lineEdit->setValidator(new QRegExpValidator(regExp));
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_lineEdit_textEdited(const QString &arg1)
{
    QString content = arg1;
    int pos = 0;
    // 验证通过
    if(ui->lineEdit->validator()->validate(content, pos) == QRegExpValidator::Acceptable)
    {
        ui->pushButton->setEnabled(true);
    }
    // 验证不通过
    else
    {
        ui->pushButton->setEnabled(false);
    }
}
